package com.example.travel.service;

import com.example.travel.mapper.RouteImgMapper;
import com.example.travel.mapper.RouteMapper;
import com.example.travel.pojo.RouteImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RouteImgService {

    @Autowired
    private RouteImgMapper routeImgMapper;

    //通过rid获取所有图片信息
    public List<RouteImg> getRouteImgByRid(Integer rid){

        return routeImgMapper.getRouteImgByRid(rid);
    }

    //通过rid删除图片信息
    public int delRouteImgInfoByRid(Integer rid){

        return routeImgMapper.delImgByRid(rid);
    }

    //添加图片信息
    public int addRouteImgInfo(RouteImg routeImg){

        return routeImgMapper.insert(routeImg);
    }

    //更新图片
    @Transactional  //开启事务
    public void updateRouteImg(Integer rid,List<RouteImg> routeImgList){
        //先删
        routeImgMapper.delImgByRid(rid);
        //后增加
        for(RouteImg routeImg : routeImgList) {

            routeImgMapper.insert(routeImg);
        }
    }
}
